﻿using System.Collections.Generic;
using GroceryList.Model.Repositories;
using NHibernate;

namespace GroceryList.Domain.Repositories
{
    public class BaseRepository<T> : IRepository<T>
        where T : class
    {
        protected readonly ISession _session;

        public BaseRepository(ISession session)
        {
            _session = session;
        }

        public IEnumerable<T> All()
        {
            return _session.QueryOver<T>().List();
        }

        public void Save(T newObj)
        {
            _session.SaveOrUpdate(newObj);
            _session.Flush();
        }
    }
}
